package doughnut.xc.Demo;

import doughnut.xc.pojo.User2;
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler;
import org.apache.poi.xssf.usermodel.XSSFComment;

/**
 * 自定义处理器
 */
public class SheetHandle implements XSSFSheetXMLHandler.SheetContentsHandler {

    private User2 user;

    @Override
    public void startRow(int startIndex) {
        if (startIndex != 0) {
            user = new User2();
        } else {
            user = null;
        }
    }

    @Override
    public void cell(String cellName, String cellValue, XSSFComment xssfComment) {
        if (user != null){
            String letter = cellName.substring(0, 1);  //每个单元名称的首字母 A  B  C
            switch (letter){
                case "A":{
                    user.setId(Long.parseLong(cellValue));
                    break;
                }
                case "B":{
                    user.setUserName(cellValue);
                    break;
                }
            }
        }
    }

    @Override
    public void endRow(int endIndex) {
        if (endIndex != 0) {
            System.out.println(user);
        }
    }

}
